package com.zachary.es.hadoop.map;

import com.alibaba.fastjson.JSON;
import com.sdyc.ndetl.model.PostStore;
import com.sdyc.ndetl.util.PostStoreHelper;
import com.zachary.es.dtd.Post;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;

import java.io.IOException;

/**
 * <pre>
 * Created with IntelliJ IDEA.
 * User: zachary.
 * Date: 2014/7/15
 * Time: 15:20
 * PC：windows'IDEA in company <br>
 * </pre>
 *
 * @author zachary.
 */
public class IndexMapper extends TableMapper<NullWritable, Text> {
    private static final Log log = LogFactory.getLog(IndexMapper.class);

    @Override
    protected void map(ImmutableBytesWritable key, Result value, Context context) throws IOException, InterruptedException {
        PostStore postStore = PostStoreHelper.convertToPostStore(value);

        Post post = new Post(postStore);

        Text result = new Text(JSON.toJSONString(post));
        context.write(NullWritable.get(), result);
    }
}
